<?php

namespace App\Models\Shop\Goods;

use App\Models\Common\CommonModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class GoodsSpu extends CommonModel
{
    use HasFactory;
    protected $table = 'goods_spu';

    public function getClassify() {
        return $this->hasOne(GoodsClassify::class,'id','classify_id');
    }

    public function getBrand() {
        return $this->hasOne(GoodsBrand::class,'id','brand_id');

    }

    public function getSku() {
        return $this->hasMany(GoodsSku::class,'spu_id','id');
    }

    public function getRecords(array $conditions) {
        $records = parent::getRecords($conditions); // TODO: Change the autogenerated stub
        if(!empty($conditions['selectBrandId'])){
            $records = $records->where('brand_id',$conditions['selectBrandId']);
        }
        if(!empty($conditions['selectClassifyId'])){
            $records = $records->where('classify_id',$conditions['selectClassifyId']);
        }

        return $records;
    }
}
